package de.mafr.jsystest.matchers;

import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

import de.mafr.jsystest.ws.Response;


/**
 * Checks if a response has the given body.
 */
public class HasContent<T> extends TypeSafeMatcher<Response<T>> {
	private final T content;

	public HasContent(T content) {
		this.content = content;
	}

	@Override
	public boolean matchesSafely(Response<T> actual) {
		return actual.getContent().equals(content);
	}

	public void describeTo(Description description) {
		description.appendText("content ").appendValue(content);
	}
	
	@Factory
	public static <T> Matcher<Response<T>> content(T content) {
		return new HasContent<T>(content);
	}
}
